package com.explorati.design_pattern.creational.singleton;

/**
 * 模仿 ErrorContext 的线程单例 
 * @author explorati
 *
 */
public class ThreadLocalInstance2 {

	private static final ThreadLocal<ThreadLocalInstance2> LOCAL = new ThreadLocal<>();
	
	private ThreadLocalInstance2(){}
	
	public static ThreadLocalInstance2 getInstance(){
		ThreadLocalInstance2 instance = LOCAL.get();
		if(instance == null){
			instance = new ThreadLocalInstance2();
			LOCAL.set(instance);
		}
		return instance;
	}
}
